package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import springfox.documentation.annotations.ApiIgnore;
import com.ruoyi.system.vo.ZsyyCreateQrCodeVo;
import com.ruoyi.system.bo.ZsyyCreateQrCodeQueryBo;
import com.ruoyi.system.bo.ZsyyCreateQrCodeAddBo;
import com.ruoyi.system.bo.ZsyyCreateQrCodeEditBo;
import com.ruoyi.system.service.IZsyyCreateQrCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 二维码数量Controller
 *
 * @author wangghua
 * @date 2021-08-09
 */
@ApiIgnore
@Api(value = "二维码数量控制器", tags = {"二维码数量管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/createQrCode")
public class ZsyyCreateQrCodeController extends BaseController {

	private final IZsyyCreateQrCodeService iZsyyCreateQrCodeService;

	/**
	 * 查询二维码数量列表
	 */
	@ApiOperation("查询二维码数量列表")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:list')")
	@GetMapping("/list")
	public TableDataInfo<ZsyyCreateQrCodeVo> list(@Validated ZsyyCreateQrCodeQueryBo bo) {
		return iZsyyCreateQrCodeService.queryPageList(bo);
	}

	/**
	 * 导出二维码数量列表
	 */
	@ApiOperation("导出二维码数量列表")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:export')")
	@Log(title = "二维码数量", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<ZsyyCreateQrCodeVo> export(@Validated ZsyyCreateQrCodeQueryBo bo) {
		List<ZsyyCreateQrCodeVo> list = iZsyyCreateQrCodeService.queryList(bo);
		ExcelUtil<ZsyyCreateQrCodeVo> util = new ExcelUtil<ZsyyCreateQrCodeVo>(ZsyyCreateQrCodeVo.class);
		return util.exportExcel(list, "二维码数量");
	}

	/**
	 * 获取二维码数量详细信息
	 */
	@ApiOperation("获取二维码数量详细信息")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:query')")
	@GetMapping("/{id}")
	public AjaxResult<ZsyyCreateQrCodeVo> getInfo(@NotNull(message = "主键不能为空")
												  @PathVariable("id") Long id) {
		return AjaxResult.success(iZsyyCreateQrCodeService.queryById(id));
	}

	/**
	 * 新增二维码数量
	 */
	@ApiOperation("新增二维码数量")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:add')")
	@Log(title = "二维码数量", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody ZsyyCreateQrCodeEditBo bo) {
		return toAjax(iZsyyCreateQrCodeService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 修改二维码数量
	 */
	@ApiOperation("修改二维码数量")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:edit')")
	@Log(title = "二维码数量", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCreateQrCodeEditBo bo) {
		return toAjax(iZsyyCreateQrCodeService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除二维码数量
	 */
	@ApiOperation("删除二维码数量")
	@PreAuthorize("@ss.hasPermi('system:createQrCode:remove')")
	@Log(title = "二维码数量" , businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iZsyyCreateQrCodeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
